package com.eascs.afterloan.controller;

import java.text.DecimalFormat;
import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.afterloan.form.DeclareSignForm;
import com.eascs.afterloan.service.DeclareSignService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;

@Controller
@RequestMapping("/declare")
public class DeclareSignController extends BaseMasterViewController {

	@Autowired
	DeclareSignService service;

	@RequestMapping("/index")
	public String index(DeclareSignForm form) {
		form.setPageSize(10);
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "declareFind");
		String o2ourl = "/declare/index";
		String billCode = form.getBillCode() == null ? "" : form.getBillCode();
		String loanUserName = form.getLoanUserName() == null ? "" : form.getLoanUserName();
		String loanBankName = form.getLoanBankName() == null ? "" : form.getLoanBankName();
		String provinceName = form.getProvinceName() == null ? "" : form.getProvinceName();
		String loanStarTime = form.getLoanStarTime() == null ? null : form.getLoanStarTime();
		String loanEndTime = form.getLoanEndTime() == null ? null : form.getLoanEndTime();
		o2ourl = UrlUtil.appendUrl(o2ourl, "billCode", billCode);
		o2ourl = UrlUtil.appendUrl(o2ourl, "loanUserName", loanUserName);
		o2ourl = UrlUtil.appendUrl(o2ourl, "loanBankName", loanBankName);
		o2ourl = UrlUtil.appendUrl(o2ourl, "provinceName", provinceName);
		o2ourl = UrlUtil.appendUrl(o2ourl, "loanStarTime", loanStarTime);
		o2ourl = UrlUtil.appendUrl(o2ourl, "loanEndTime", loanEndTime);
		o2ourl = o2ourl + "&pageIndex=";
		PageResult<Object[]> pageResult = service.queryByPage(form);
		SelectDataOption[] selectDataOptions = { null, null, new SelectDataOption("REGIONALNAME_SB"), null, new SelectDataOption("BANKTYPEO2O"), null, null, null };
		String titles[] = { "贷款单号", "借款人姓名", "省区", "平台", "放款银行", "放款日期", "放款金额(万元)", "状态", "更新时间", "更新人" };
		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, o2ourl);
		o2oPagingInfo.setBuildPagingNavigation(true);
		o2oPagingInfo.setFirstRenderColumnIndex(0);
		o2oPagingInfo.setSelectDataOptions(selectDataOptions);
		o2oPagingInfo.setFormats(new Format[] { null, null, null, null, null, null, new DecimalFormat(",##0.00"), null, null, null });
		ViewContext.put("vo", form);
		ViewContext.put("paginationInfo", o2oPagingInfo);
		return "afterloan/declare_index";
	}
}
